package chs;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that beats SitingDuck.
 *
 * @author Sean
 */
public class TestAtomCenter extends RobotTestBed {
  boolean centered;
 
  /**
   * Specifies that SittingDuck and Atom are to be matched up in this test case.
   *
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Walls, chs.Atom";
  }

  /**
   * This test runs for 10 round.
   *
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * Returns a comma or space separated list like: x1,y1,heading1, x2,y2,heading2, which are the 
   * coordinates and heading of robot #1 and #2. So "0,0,180, 50,80,270" means that robot #1 
   * has position (0,0) and heading 180, and robot #2 has position (50,80) and heading 270.
   * 
   * Override this method to explicitly specify the initial positions for your test cases. 
   * 
   * Defaults to null, which means that the initial positions are determined randomly.  Since
   * battles are deterministic by default, the initial positions are randomly chosen but will
   * always be the same each time you run the test case. 
   * 
   * @return The list of initial positions.
   */
  @Override
  public String getInitialPositions() {
    // Try to place Walls and Atom in a location where Walls won't be hit for 4 turns at least,
    // causing Atom to move to the center
    return "800,600,90, 0,0,0";
  }
  
  /**
   * Check that robot gets to the center of the battlefield.
   *
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {    
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double xPos = robot.getX();
    double yPos = robot.getY();
    
    // Default battlefield is 800 x 600
    if ((xPos == 400) && (yPos == 300)) {
      centered = true;
    }
  }
  
  /**
   * After the battle, check to see that Atom was walling the entire time.
   *
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Centered", centered);
  }
}
